import { useReducer } from 'react';
import { Button } from 'antd';

const init = 0;
const reducer = (state: number, action: any) => {
  switch (action) {
    case 'inc':
      return state + 1;
    case 'dec':
      return state - 1;
    case 'reset':
      return 0;
    default:
      throw new Error(`unExpected action ${action}`);
  }
};

const Test = () => {
  const [count, dispatch] = useReducer(reducer, init);
  return (
    <div>
      count is :{count}
      <Button onClick={() => dispatch('inc')}>+1</Button>
      <Button onClick={() => dispatch('dec')}>-1</Button>
      <Button onClick={() => dispatch('reset')}>to 0</Button>
    </div>
  );
};

export default Test;
